package com.xm.xmapp;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.app.Type;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.customview.CustomLayoutText;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Cancel_refundRequset;
import com.xm.xmapp.response.bean.ResponseAccountRecord;
import com.xm.xmapp.tools.StringTools;

public class AccountRecordDetailActivity extends BaseActivity implements OnClickListener {

	private ResponseAccountRecord bean;
	private CustomLayoutText cl_status, cl_order_sn, cl_add_time, cl_operat_type, cl_amount, cl_remark, cl_pay_type,
			cl_mstatus, cl_donate_money;
	private TextView submit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_account_detail);
	}

	@Override
	public void initView() {

		cl_status = (CustomLayoutText) findViewById(R.id.cl_status);
		cl_order_sn = (CustomLayoutText) findViewById(R.id.cl_order_sn);
		cl_add_time = (CustomLayoutText) findViewById(R.id.cl_add_time);
		cl_operat_type = (CustomLayoutText) findViewById(R.id.cl_operat_type);
		cl_amount = (CustomLayoutText) findViewById(R.id.cl_amount);
		cl_remark = (CustomLayoutText) findViewById(R.id.cl_remark);
		cl_pay_type = (CustomLayoutText) findViewById(R.id.cl_pay_type);
		cl_mstatus = (CustomLayoutText) findViewById(R.id.cl_mstatus);
		cl_donate_money = (CustomLayoutText) findViewById(R.id.cl_donate_money);
		submit = (TextView) findViewById(R.id.submit);
	}

	@Override
	public void initData() {

		setMyTitle("账单详情");
		bean = (ResponseAccountRecord) getIntent().getSerializableExtra("bean");
		if (bean.is_success == 1) {
			cl_status.setText2("已完成");
		} else {
			cl_status.setText2("未完成");
		}
		cl_order_sn.setText2(bean.order_sn);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日   HH:mm:ss     ");
		Date curDate = new Date(bean.add_time * 1000);
		// 获取当前时间
		String str = formatter.format(curDate);
		cl_add_time.setText2(str);
		cl_operat_type.setText2(bean.money_user_way_text);
		if (bean.process_type == 2) {// 退款隐藏支付方式
			cl_pay_type.setVisibility(View.GONE);
		}
		cl_amount.setText2(StringTools.formatFloatNumber(bean.amount) + "元");
		cl_pay_type.setText2(StringTools.getPayWay(bean.payment_type));
		if (bean.donate_money > 0) {
			cl_donate_money.setVisibility(View.VISIBLE);
			cl_donate_money.setText2(StringTools.formatFloatNumber(bean.donate_money) + "元");
		} else {
			cl_donate_money.setVisibility(View.GONE);
		}

		if (bean.amount < 0) {
			cl_amount.getTextView2().setTextColor(ContextCompat.getColor(this, R.color.red_text_color));
		} else {
			cl_amount.getTextView2().setTextColor(ContextCompat.getColor(this, R.color.green_color_text));
		}

		if (bean.remark == null || bean.remark.equals("")) {
			cl_remark.setVisibility(View.GONE);
		} else {
			cl_remark.setText2(bean.remark);
		}

		if (bean.is_success == 1) {
			cl_mstatus.setText2("成功");
			cl_mstatus.setText2Color("#4DAB68");
		} else {
			cl_mstatus.setText2("失败");
			if (bean.handle_time == 0 && bean.process_type == 2) {
				cl_mstatus.setText2("处理中");
				if (bean.type == 2 || bean.type == 3) {
					submit.setVisibility(View.VISIBLE);
				} else {
					submit.setVisibility(View.GONE);
				}
			}
		}

	}

	@Override
	public void initEvent() {
		submit.setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {

		case R.id.submit:

			promptDialog.show();
			Cancel_refundRequset requestBean = new Cancel_refundRequset();
			requestBean.account_record_id = bean.account_record_id;
			MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

				@Override
				public void onResponse(String response) {

					promptDialog.dismiss();
					MyAppcation.getMyAppcation().notifyDataSetChanged(AccountRecordListActivity.class,
							Type.A_AccountRecordList.REFRESH, null);
					finish();
				}
			}, new DisssmissInterFace() {

				@Override
				public void putError(VolleyError error) {
					promptDialog.dismiss();

				}
			});

			break;

		default:
			break;
		}
	}
}
